package com.aaa.controller.sds;

import cn.hutool.core.util.ObjectUtil;
import com.aaa.aspect.LogMonitor;
import com.aaa.controller.BaseController;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.Result;
import com.aaa.entity.sds.TestResultSds;
import com.aaa.entity.sds.ViewTestResultSds;
import com.aaa.service.sds.ViewTestResultSdsService;
import com.github.pagehelper.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * (ViewTestResultMht)表控制层
 *
 * @author makejava
 * @since 2022-09-05 19:41:05
 */
@RestController
@RequestMapping("viewTestResultSds")
public class ViewTestResultSdsController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private ViewTestResultSdsService viewTestResultSdsService;

    @ResponseBody
    @RequestMapping("/queryAll.do")
    public Result queryAll(PageSortEntity page, ViewTestResultSds viewTestResultSds) {
        Page pg = viewTestResultSdsService.queryAll(page, viewTestResultSds);
        return success(pg.getResult(), pg.getTotal());
    }

    @LogMonitor
    @ResponseBody
    @RequestMapping("/delete.do")
    public Result queryAll(String id) {
        boolean delete = viewTestResultSdsService.delete(id);
        if (delete) {
            return success();
        }
        return fail();
    }

    @ResponseBody
    @RequestMapping("/queryResultById.do")
    public Result queryResultById(Integer id) {
        ViewTestResultSds vs = viewTestResultSdsService.queryResultById(id);
        if (ObjectUtil.isNotEmpty(vs)) {
            return success(vs);
        }
        return fail();
    }

    @ResponseBody
    @RequestMapping("/queryAllPlan.do")
    public Result queryAllPlan() {
        Map<String, Integer> map = viewTestResultSdsService.queryAllPlanSds();
        if (ObjectUtil.isNotEmpty(map)) {
            return success(map);
        }
        return fail();
    }
    /**
     * @create by: 周文达
     * @description: 查询个人答题详情
     * @create time: 2022/9/13 8:31
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping("/selectAllByPerson.do")
    public Result selectAllByPerson(PageSortEntity page, TestResultSds id) {
        Page viewPersonResultSds = viewTestResultSdsService.selectAllByPerson(page,id);
        return success(viewPersonResultSds.getResult(), viewPersonResultSds.getTotal());
    }

}

